IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SaveResearchFinanceInfo]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[SaveResearchFinanceInfo]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    
/***************************************************************************    
* Name:   SaveResearchFinanceInfo    
* Purpose:  Insert/Update a ResearchFinanceInfo. If the id is 0, then a new     
*    record is inserted, else the record with the specified id is updated    
*    
* PARAMETERS    
* Name      Description         
* -------------    -----------------------------------------------------------    
* @id      unique id    
* @fwkDomainOrganizationId FwkDomainOrganizationId    
* @admSponsorTypeId   AdmSponsorTypeId    
* @admPersonId    AdmPersonId    
***************************************************************************/    
CREATE PROCEDURE dbo.[SaveResearchFinanceInfo]    
(    
 @id INT,    
 @fwkDomainOrganizationId INT,    
 @admSponsorTypeId INT,    
 @admPersonId INT,    
 @roleId INT  
)    
AS    
BEGIN    
 SET NOCOUNT ON    
    
 -- if it's zero, then insert    
 IF @id = 0     
 BEGIN    
      
  INSERT INTO dbo.AdmResearchFinanceInfo ( [FwkDomainOrganizationId],    
     AdmSponsorTypeId, AdmPersonId, DateCreated, DateLastModified ,RoleId)    
    Values ( @fwkDomainOrganizationId, @admSponsorTypeId, @admPersonId,    
     GetDate(), GetDate(),@roleId)    
     
  IF @@ERROR <> 0 GOTO ERROR_HANDLER     
      
  SELECT SCOPE_IDENTITY()    
      
  RETURN    
    
 END    
 -- else update    
 ELSE    
 BEGIN    
  UPDATE dbo.AdmResearchFinanceInfo SET    
     FwkDomainOrganizationId   = @fwkDomainOrganizationId,    
     AdmSponsorTypeId = @admSponsorTypeId,    
     AdmPersonId   = @admPersonId,    
     DateLastModified = GetDate() ,  
     RoleId = @roleId  
   WHERE Id = @id    
     
  IF @@ERROR <> 0 GOTO ERROR_HANDLER    
    
  SELECT @id     
  RETURN    
 END    
     
 ERROR_HANDLER:    
  RAISERROR('Unable to save AdmResearchFinanceInfo', 16, 1)    
  RETURN    
      
    
 SET NOCOUNT OFF    
END    
GO
